<?php

namespace App\Modules\System\Models;


use Illuminate\Database\Eloquent\Model;

/**
 * Class Task 用餐时间段
 * @package App\Modules\Task\Models
 */
class DiningTime extends Model
{
    protected $table = 'diningtime';

    protected $fillable = ['id','user_id', 'meals', 'start_time', 'end_time', 'before_low', 'before_high', 'after_low', 'after_high', 'created_at', 'updated_at', 'status'];

    /**
     * 用餐时间段列表
     */
    static function getList($user_id)
    {
        return self::select(['id','meals','start_time','end_time'])->where('user_id',$user_id)->where('status',1)->get()->toArray();
    }

    /**
     * 获取用餐时间段详情
     * @param $id 任务id
     * @return mixed
     */
    static function getDiningTime($id)
    {
        return self::where('id',$id)->first();
    }

    /**
     * 添加用餐时间段
     * @param $param
     * @return mixed
     */
    static function addDiningTime($param)
    {
        // TODO check
        return self::create($param);
    }

    /**
     * 更新用餐时间段
     * @param $param
     * @return mixed
     */
    static function updateDiningTime($param)
    {
        // TODO check
        return self::where('id',$param['id'])->where('user_id',$param['user_id'])->update($param);
    }

}